-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds an exists?
class method
#343
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@amberframework/contributors Any other feedback? If not, I will merge. |
Hm, I think I'd expect the syntax to be The type based overloading makes me a little nervous, but I think it's well thought out. |
@robacarp That's also an option. What would we do if they did like It should be all tested as well. Helped clean everything up a bit. |
@Blacksmoke16 man it'd be great if it weren't possible by compile-time-enforcement to call #exists? on a query which had #limit called on it. However, I think that's a bigger refactor than is needed here, and that just raising a runtime warning of some sort is fine. To be clear, I don't think having a Class#exists? method is mutually exclusive with a Class#where()#exists?, I think we can provide both. |
Right, as long as we're OK with just ignoring other parts of the query I can implement this. Im imaging it to just be a new assembler method like |
Cleans up some code
@robacarp I added that if you wanted to review again. Going to see if the MySQL issue will be resolved soon, otherwise I'll monkey patch it and can remove the patch when it does. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the one comment.
Refactor the build_find_by_clause method
@robacarp that's updated. I also set the MySQL shard to the latest commit so that CI passes, as crystal-lang/crystal-mysql#78 got merged. Can be changed back to the version string next time a new release is made. |
@drujensen thoughts on targeting a non-release version of mysql? A commit hash is just as unique as a version number but since it's pinned to the exact commit could it cause version conflicts with projects which require mysql themselves? @Blacksmoke16 any idea when that'll be released to a numbered version? |
It's in PR to be released. I changed it back to use the version string. Will rerun CI when it is released. |
@robacarp looks like 0.7.0 will be released soon crystal-lang/crystal-mysql#79 |
Should be good to go now @drujensen @robacarp |
thanks as always @Blacksmoke16 |
Adds a method that will return true if a record exists that matches the provided criteria, or false otherwise. Based off of ActiveRecord.exists?.
String
orNumber
, attempts to lookup a records with a PK with that value.Hash
orNamedTuple
, attempts to lookup a record that matches the given criteria.find_by(Hash)
, and to share some code betweenexists?
andfind_by
find_by
that made it not correctly match nil values.Array
andUUID
values.